package com.example.ch04_03_t;

import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
	private Button btnDafault;
	private Button btnCustLayoutCode;
	private Button btnCustLayoutXML;
	private Button btnCustPosition;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		initHandler();
	}

	private void initHandler() {
		// TODO Auto-generated method stub
		btnDafault.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(MainActivity.this, "Default Type Toast",
						Toast.LENGTH_SHORT).show();
			}
		});
		btnCustPosition.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast t = Toast.makeText(MainActivity.this,"Custom position Toast", Toast. 
						LENGTH_LONG);
				t.setGravity(Gravity. CENTER, 0, 0);
				t.show();
			}
		});
		btnCustLayoutXML.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast toast = new Toast(MainActivity.this);
				toast.setGravity(Gravity.CENTER| Gravity.LEFT, 0, 0);
				LayoutInflater inflater = getLayoutInflater();
				View view = inflater.inflate(R.layout.toast_my, ((ViewGroup) findViewByld(R.id.rootLayout)))
			}
		});
	private void initView() {
		// TODO Auto-generated method stub
		btnDafault = (Button)this.findViewById(R.id.btn_dafault);
		btnCustPosition = (Button)this.findViewById(R.id.btn_custPosition);
		btnCustLayoutXML = (Button)this.findViewById(R.id.btn_custLayoutXML);
		btnCustLayoutCode = (Button)this.findViewById(R.id.btn_custLayoutCode);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
